var $;
/**
 * Created by tianrui on 2018/1/29 0029.
 */
// var $;
layui.config({
    base : "js/"
}).use(['form','layer','jquery','laypage'],function(){
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage;
         $ = layui.jquery;



    $.ajax({
        url : "http://localhost/ci/admin/department/dep_edit",
        type : "post",
        data : {'id':parent.$('.ci_data').val(), 'token':localStorage.token,'user_token':localStorage.user},
        dataType : "json",

        success : function(data){

          //var arr= JSON.stringify(data['department'])
            console.log(data['department']);
             //$('.id').val(data['department'].id);
            $('.departmentname').val(data['department']['name']);
            $('.departmenttext').val(data['department']['text']);
            top.layer.msg("用户回显成功！");
        },
        error : function (data) {
             console.log(data);
            top.layer.msg("用户回显失败！");
        }
    })
    // console.log(data);
    //
    var addDepratmentArray = [],updateDepartement = [];
    form.on("submit(update)",function(data){
        updateDepartement= '{"id":"'+parent.$('.ci_data').val()+'","name":"'+ $('.departmentname').val() + '","text":"'+ $('.departmenttext').val() +'"}';
        console.log(updateDepartement)
        $.ajax({
            url : "http://localhost/ci/admin/department/dep_update",
            type : "post",
            data : {'data':updateDepartement, 'token':localStorage.token,'user_token':localStorage.user},
            dataType : "json",
            success : function(data){
                 console.log(data);
                // top.layer.close();
                top.layer.msg("用户修改成功！");
                layer.closeAll("iframe");
                //刷新父页面
              parent.location.reload();
            },
            error : function (data) {
                console.log(data);
                //top.layer.close(index);
                top.layer.msg("用户修改失败！");
                layer.closeAll("iframe");
                //刷新父页面
                 parent.location.reload();
            }
        })
        return false;
    })

})

